<template>
  <div class="header">
    <div class="logo">
      <img src="../../assets/img/logo.png" alt="">
    </div>
    <div class="name">中国宝武组织绩效及“一人一表”管理系统</div>
    <div class="date">
      <el-select v-model="date" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </div>
    <div class="user">
      <p class="pwd" @click="modiPwd">
        <i class="icon" />
        <span class="pspan1">修改密码</span>
      </p>
      <p class="line">|</p>
      <p class="name1">
        <span class="pspan2">您好，{{ userName }}</span>
        <i class="loginOut" @click="loginOutClick()" />
      </p>
    </div>
    <!-- 弹窗 -->
    <el-dialog
      class="mydialog"
      title="修改密码"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
      append-to-body
      style="font-size: 12px !important"
      top="25vh"
    >
      <div :key="subKey" class="main">
        <el-form
          ref="ruleForm"
          status-icon
          label-width="110px"
          class="demo-ruleForm"
        >
          <el-form-item label="原密码" prop="pass">
            <el-input
              v-model="ruleForm.oldPassword"
              type="password"
              autocomplete="off"
              placeholder="请输入原密码"
            />
          </el-form-item>
          <el-form-item label="新密码" prop="pass">
            <el-input
              v-model="ruleForm.newPassword"
              type="password"
              autocomplete="off"
              placeholder="请输入新密码"
              maxlength="16"
            />
          </el-form-item>
          <el-form-item label="确认新密码" prop="repeatPassword">
            <el-input
              v-model="ruleForm.repeatPassword"
              type="password"
              autocomplete="off"
              placeholder="请再次输入新密码"
              maxlength="16"
            />
          </el-form-item>
          <div class="submit">
            <el-button type="primary" @click="subconfirm()">确认</el-button>
            <el-button @click="cancelConfirm()">取消</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: {
    // userName: {
    //   type: String,
    //   default: ''
    // }
  },
  data() {
    return {
      date: '2021',
      userName: '',
      subKey: 0,
      options: [
        {
          value: '2021',
          label: '2021'
        },
        {
          value: '2020',
          label: '2020'
        }
      ],
      dialogVisible: false,
      ruleForm: {
        oldPassword: '',
        newPassword: '',
        repeatPassword: ''
      },
      menuEname: '',
      navBarList: []
    }
  },
  watch: {
    date(val) {
      // console.log(val)
      this.$emit('date', val)
    }
  },
  mounted() {
    this.$emit('date', this.date)
    this.init()
  },
  methods: {
    loginOutClick() {
      console.log('登出')
      window.location.href = '/opm/login.jsp'
    },
    init() {
      this.$http.post('/serviceAction/common', {
        'serviceName': 'MT01108',
        'methodName': 'getUserInfo'
      }).then((res) => {
        this.userName = res.data.empName
      })
    },
    modiPwd() {
      this.ruleForm.oldPassword = ''
      this.ruleForm.newPassword = ''
      this.ruleForm.repeatPassword = ''

      this.dialogVisible = true
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
    // 修改密码--确认
    subconfirm() {
      // console.log('subconfirm', this.ruleForm)
      if (this.ruleForm.newPassword === this.ruleForm.repeatPassword) {
        this.$http.post('/serviceAction/common', {
          'serviceName': 'MT01001',
          'methodName': 'savePassword',
          ...this.ruleForm
        }).then((res) => {
          console.log(res)
          if (res.isSuccess === true) {
            // this.todoList = res.data
            this.$message({
              type: 'success',
              message: '修改成功'
            })
            this.dialogVisible = false
            window.location.href = '/opm/login.jsp'
          } else {
            this.$message({
              type: 'info',
              message: res.message
            })
          }
        })
      } else {
        this.$message({
          type: 'info',
          message: '新密码与确认新密码不一致'
        })
      }
    },
    // 修改密码--取消
    cancelConfirm() {
      console.log('cancelConfirm')

      this.$confirm('确认关闭？')
        .then((_) => {
          this.dialogVisible = false
        })
        .catch((_) => {})
    }
  }
}
</script>
<style lang="scss">
.mydialog {
  .el-dialog {
    width: 430px !important;
    height: 310px;
    .el-dialog__header {
      height: 45px;
      padding: 15px 15px 0 30px;
      .el-dialog__title {
        position: relative;
        font-size: 14px;
        font-weight: 600;
        line-height: 7px;
        &::before {
          content: "";
          position: absolute;
          top: 1px;
          left: -10px;
          display: block;
          width: 3px;
          height: 14px;
          background-color: #4b92f7;
        }
      }
      .el-dialog__headerbtn {
        top: 12px;
      }
    }
  }
  .el-dialog__body {
    padding: 0;
    .main {
      width: 390px;
      margin: 0 auto;
      // height: 40px;
      border-top: 1px solid #d4d4d4;
      padding-top: 26px;
      .el-form-item {
        margin-bottom: 8px;
        .el-form-item__label {
          color: #303133;
        }
        .el-form-item__content {
          width: 245px;
          .el-input__inner {
            border-radius: 2px;
          }
        }
      }
      .submit {
        margin-top: 32px;
        width: 100%;
        padding: 0 80px;
        .el-button {
          width: 95px;
          height: 36px;
          border-radius: 18px;
          font-size: 17px;
        }
        .el-button--default{
          margin-left: 40px;
          color: #b9b9b9;
        }
      }
    }
  }
}
</style>
<style scoped lang="scss">
.header {
  height: 60px;
  width: 100%;
  position: fixed;
  top: 0px;
  left: 0px;
  background: url("../../assets/img/navbg.png") no-repeat;
  font-size: 12px;
  .logo {
    float: left;
    width: 143px;
    margin: 15px 0 0 20px;
    img {
      width: 100%;
    }
  }
  .name {
    margin: 18px 0 0 20px;
    color: #fff;
    float: left;
    font-size: 20px;
    font-weight: 600;
  }
  .user {
    float: right;
    padding-right: 20px;
    .line {
      position: relative;
      top: 4px;
      padding: 0 10px;
    }
    p {
      float: left;
      margin: 20px 0 0 0px;
      color: #fff;
      font-size: 12px;
      .pspan1 {
        padding-left: 4px;
        cursor: pointer;
      }
      .pspan2 {
        padding-right: 10px;
      }
      .icon {
        position: relative;
        top: 3px;
        display: inline-block;
        width: 15px;
        height: 15px;
        background: url("../../assets/img/code.png") no-repeat;
        background-size: 13px;
      }
      .loginOut {
        position: relative;
        top: 4px;
        display: inline-block;
        width: 15px;
        height: 15px;
        background: url("../../assets/img/quit.png") no-repeat;
        background-size: 13px;
        cursor: pointer;
      }
    }
  }
}
::v-deep {
  .date {
    width: 114px;
    margin-top: 17px;
    margin-left: 20px;
    float: left;
    .el-input__inner {
      border-radius: 30px;
    }
    .el-select .el-input.is-focus .el-input__inner,
    .el-select .el-input__inner:focus {
      border-color: rgba(0, 0, 0, 0);
    }
  }
}
</style>
